package cn.wsalix.web;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.admin.form.UserForm;

@Aspect
@Service("wsalixAspect")
public class WsalixAspect {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Pointcut("execution(* cn.wsalix.*.web.*Action.*(..))")
	public void checkToken() {
	};

	@Before("checkToken()")
	public void before(JoinPoint call) {
		logger.info("【注解-前置通知】:方法正常结束了");
		Object[] args = call.getArgs();
		if (args.length == 1) {
			if (args[0] instanceof UserForm) {

			}
		}
	}

	@Transactional
	@Around("checkToken()")
	public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
		// start stopwatch
		Object retVal = pjp.proceed();
		if (retVal instanceof Boolean) {
			Boolean val = (Boolean) retVal;
			if (val) {

			}
		}
		// stop stopwatch
		// 这里，这里，这里添加代码，你就把retVal想干嘛就干嘛，然后再返回
		return retVal;
	}

	@AfterReturning("checkToken()")
	public void afterReturn(JoinPoint call) {
		logger.info("【注解-后置通知】:方法正常结束了");
	}

}
